import { ScrollView, View } from "@tarojs/components";
import { CSSProperties, ReactNode } from "react";
import styles from "./style.scss";

type Props<T> = {
  style?: CSSProperties;
  loading?: boolean;
  data?: T[];
  renderItem: (item: T, index: number, arr: T[]) => ReactNode;
};

export default <T = any,>(props: Props<T>) => {
  const { style, loading, data, renderItem } = props;

  return (
    <View className={styles.scrollView} style={style}>
      <View className={styles.list}>{data?.length ? data?.map(renderItem) : loading}</View>
      {loading ? (
        <View className={styles.tip}>加载中 ···</View>
      ) : (
        <View className={styles.tip}>没有啦～</View>
      )}
    </View>
  );
}
